const jwt = require('jsonwebtoken')

const Token = {
    //加密token username,id存储在token中, Time为过期时间
    encryptionToken(_id, jwt_key) {
        let token = jwt.sign(
            {_id},
            jwt_key,
            { expiresIn: 60 * 60 * 72 }
        )
        return token
    },

    // 解密token 
    decryptToken(token,jwt_key){
        try{
            let tokenKey = jwt.verify(token,jwt_key);
            return tokenKey
        }catch{
            return 'tokenKey is error'
        }
    }
}

module.exports = Token
